/* *****************************************************************************
 * JFab (http://code.google.com/p/jfab)
 * Copyright (c) 2011 JFab.org
 * Admin jfab@jeffreythompson.net
 *
 * See the file "LICENSE.txt" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * *****************************************************************************/

package org.jfab.core.factory;

import org.apache.commons.lang3.Validate;
import org.jfab.core.collection.CGAnnotationList;
import org.jfab.core.collection.CGParameterList;
import org.jfab.core.collection.CGTypeList;
import org.jfab.core.collection.CommentList;
import org.jfab.core.collection.MethodBodyList;
import org.jfab.core.collection.ModifierList;
import org.jfab.core.model.CGConstructor;

/**
 * Provides a constructor factory.
 */
public final class DefaultCGConstructorFactory implements CGConstructorFactory
{
    @Override
    public final CGConstructor createConstructor(
            final CGTypeList referencedTypes, final CommentList commentLines,
            final CGAnnotationList annotations, final ModifierList modifiers,
            final String className, final CGParameterList parameters,
            final CGTypeList throwsTypes, final MethodBodyList methodBodyLines)
    {
        Validate.notEmpty(className, "className is empty");

        final CGConstructor answer = new CGConstructor();

        if (referencedTypes != null)
        {
            answer.getReferencedTypes().addAll(referencedTypes);
        }

        if (annotations != null)
        {
            answer.getAnnotations().addAll(annotations);
        }

        answer.setName(className);

        if (commentLines != null)
        {
            answer.getCommentLines().addAll(commentLines);
        }

        if (methodBodyLines != null)
        {
            answer.getMethodBodyLines().addAll(methodBodyLines);
        }

        if (modifiers != null)
        {
            answer.getModifiers().addAll(modifiers);
        }

        if (parameters != null)
        {
            answer.getParameters().addAll(parameters);
        }

        if (throwsTypes != null)
        {
            answer.getThrowsTypes().addAll(throwsTypes);
        }

        return answer;
    }

    @Override
    public final CGConstructor createNoArgConstructor(
            final CGTypeList referencedTypes, final CommentList commentLines,
            final CGAnnotationList annotations, final ModifierList modifiers,
            final String className, final CGTypeList throwsTypes,
            final MethodBodyList methodBodyLines)
    {
        final CGParameterList parameters = null;

        return createConstructor(referencedTypes, commentLines, annotations,
                modifiers, className, parameters, throwsTypes, methodBodyLines);
    }
}
